using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;


namespace Cassandraemon.Util
{


	class ExpressionAnalyzer : ExpressionVisitor
	{
		private readonly string[] SupportedMethod = new string[]{"Where", "CountColumn", "FirstColumn", "FirstOrDefaultColumn", "LastColumn", "LastOrDefaultColumn", "ReverseColumn", "TakeColumn", "Take"};
				
		
		public Expression CassandraExpression { get; set; }
		

		public ExpressionAnalyzer ()
		{
		}
		
		
		public void Analyze(Expression expression)
		{
			base.Visit(expression);
		}
		
		protected override Expression VisitMethodCall(MethodCallExpression expression)
		{
			if(CassandraExpression == null)
			{
				if(SupportedMethod.Contains(expression.Method.Name))
				{
					CassandraExpression = expression;
				}
				else
				{
					base.Visit(expression.Arguments[0]);
				}
			}
			return expression;
		}
	}
}
